'use strict';

const Controller = require('egg').Controller;

/**
 * 200=成功
 * 301-399=错误码 
 */
class XlslController extends Controller {
    /**
     * 指定位置插入数据
     */
    async insert() {
        const { ctx } = this;
        let xlsx = require('xlsx');

        let workbook = xlsx.readFile('D:/Users/Administrator/Documents/开发测试/企业年龄.xlsx'); //workbook就是xls文档对象

        let sheetNames = workbook.SheetNames; //获取表明

        let sheet = workbook.Sheets[sheetNames[0]]; //通过表明得到表对象

        var data = xlsx.utils.sheet_to_json(sheet); //通过工具将表对象的数据读出来并转成json
        ctx.body = {
            code: 200,
            msg: "成功",
            data: data
        };
    }

}

module.exports = XlslController;